package com.linsen.core.lock.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Redis连接方式
 * <p>
 * 包含:standalone-单节点部署方式
 * sentinel-哨兵部署方式
 * cluster-集群方式
 * masterslave-主从部署方式
 * </p>
 * @author zhaoyong
 * @date 2023/3/21
 */
@Getter
@AllArgsConstructor
public enum RedisConnectionType {

    STANDALONE("standalone", "单节点部署方式"),
    SENTINEL("sentinel", "哨兵部署方式"),
    CLUSTER("cluster", "集群方式"),
    MASTERSLAVE("masterslave", "主从部署方式");

    @JsonValue
    private final String connection_type;
    private final String connection_desc;

    private static final Map<String, RedisConnectionType> VALUES = new HashMap<>();

    static {
        for (final RedisConnectionType redisConnectionType : RedisConnectionType.values()) {
            RedisConnectionType.VALUES.put(redisConnectionType.getConnection_type(), redisConnectionType);
        }
    }

    @JsonCreator
    public static RedisConnectionType getByValue(String value) {
        return RedisConnectionType.VALUES.get(value);
    }
}
